//
//  GTNewsViewController.m
//  SampleApp2
//
//  Created by GXHC on 2023/6/7.
//

#import "../Detail/Controller/NewsDetailViewController.h"
#import "../Video/GTVideoViewController.h"
#import "GTNewsViewController.h"
#import "../Layout/GTLayoutViewController.h"
#import "../View/GTCommentManager.h"
#import "../Map/GTMapViewController.h"
#import "../NVideo/NVideoViewController.h"
@interface GTNewsViewController ()<UIGestureRecognizerDelegate>
-(void) _showComment;
@end

@implementation GTNewsViewController

- (instancetype)init {
    self = [super init];

    if (self) {
        self.tabBarItem.title = @"新闻";
        self.tabBarItem.image = [UIImage imageNamed:@"page"];
        self.tabBarItem.selectedImage = [UIImage imageNamed:@"page_selected"];
    }

    return self;
}

/// 加载
- (void)viewDidLoad {
    [super viewDidLoad];

    self.view.backgroundColor = [UIColor whiteColor];
    // Do any additional setup after loading the view.
  
	[self.view addSubview:({
		UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
		//	button.backgroundColor = [UIColor greenColor];
		[button setTitle:@"跳转到详情页面" forState:(UIControlStateNormal)];
	//    [button setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
		[button addTarget:self action:@selector(pushController) forControlEvents:(UIControlEventTouchUpInside)];

		button.titleLabel.textColor = [UIColor whiteColor];
		button.frame = CGRectMake(150, 150, 100, 100);
		button;
	})];

    

	[self.view addSubview:({
		UILabel *label = [[UILabel alloc]initWithFrame:CGRectMake(100, 200, 200, 100)];
		label.text = @"新布局页面";
		label.numberOfLines = 1;
		label.lineBreakMode = NSLineBreakByTruncatingTail;
		label.font = [UIFont systemFontOfSize:20];
		label.textColor = [UIColor redColor];
		label.textAlignment = NSTextAlignmentCenter;
		label.shadowColor = [UIColor magentaColor];
		label.shadowOffset = CGSizeMake(2, 1);
		UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushLayoutController)];
		tap.delegate = self;
		label.userInteractionEnabled = YES;
		[label addGestureRecognizer:tap];
		label;
	})];

   
	[self.view addSubview:({
		UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(140, 300, 100, 100)];
		UIImage *image = [UIImage imageNamed:@"icon"];
		imageView.image = image;

		imageView.userInteractionEnabled = YES;
		[imageView addGestureRecognizer:({
			UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self
																				  action:@selector(pushVideoController)];
			tap;
		})];
		imageView;
	})];
	
	[self.view addSubview:({
		UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
		//	button.backgroundColor = [UIColor greenColor];
		[button setTitle:@"输入框页面" forState:(UIControlStateNormal)];
	//    [button setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
		[button addTarget:self action:@selector(_showComment) forControlEvents:(UIControlEventTouchUpInside)];

		button.titleLabel.textColor = [UIColor whiteColor];
		button.frame = CGRectMake(150, 380, 100, 100);
		button;
	})];
	
	[self.view addSubview:({
		UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
		//	button.backgroundColor = [UIColor greenColor];
		[button setTitle:@"地图页面" forState:(UIControlStateNormal)];
	//    [button setImage:[UIImage imageNamed:@"icon"] forState:UIControlStateNormal];
		[button addTarget:self action:@selector(_pushMapController) forControlEvents:(UIControlEventTouchUpInside)];

		button.titleLabel.textColor = [UIColor whiteColor];
		button.frame = CGRectMake(150, 420, 100, 100);
		button;
	})];
	
	[self.view addSubview:({
		UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
		[button setTitle:@"替换图标" forState:(UIControlStateNormal)];
		button.layer.masksToBounds = YES;
		button.layer.borderWidth = 1;
		button.layer.cornerRadius = 10;
		button.layer.borderColor = [UIColor blueColor].CGColor;
		[button addTarget:self action:@selector(_replaceIcon) forControlEvents:(UIControlEventTouchUpInside)];
		button.titleLabel.textColor = [UIColor whiteColor];
		button.frame = CGRectMake(150, 480, 100, 100);
		button;
	})];
	
	[self.view addSubview:({
		UIButton *button = [UIButton buttonWithType:UIButtonTypeDetailDisclosure];
		[button setTitle:@"新的视频页面" forState:(UIControlStateNormal)];
		[button addTarget:self action:@selector(_videoLayout) forControlEvents:(UIControlEventTouchUpInside)];
		button.titleLabel.textColor = [UIColor whiteColor];
		button.frame = CGRectMake(150, 550, 100, 100);
		button;
	})];
	
}

-(void)_videoLayout{
	NVideoViewController *mapView = [[NVideoViewController alloc]init];

	mapView.view.backgroundColor = [UIColor whiteColor];
	mapView.navigationItem.title = @"视频列表页面";
	[self.navigationController pushViewController:mapView animated:YES];
}

- (void) _replaceIcon{
	if([UIApplication sharedApplication].supportsAlternateIcons){
		[[UIApplication sharedApplication] setAlternateIconName:@"ICONBLACK" completionHandler:^(NSError * _Nullable error) {
					NSLog(@"");
		}];
	}
}

- (void) _pushMapController{
	GTMapViewController *mapView = [[GTMapViewController alloc]init];

	mapView.view.backgroundColor = [UIColor whiteColor];
	mapView.navigationItem.title = @"地图页面";
	[self.navigationController pushViewController:mapView animated:YES];
}

-(void) _showComment{
	[[GTCommentManager shareManager] showCommentVIew];
}


- (void) pushLayoutController {
	GTLayoutViewController *layoutView = [[GTLayoutViewController alloc]init];

	layoutView.view.backgroundColor = [UIColor whiteColor];
	layoutView.navigationItem.title = @"布局页面";
	//	detailViewController.navigationItem.backButtonTitle = @"返回";
	[self.navigationController pushViewController:layoutView animated:YES];
}

/// 视频页面
- (void)pushVideoController {
    GTVideoViewController *videoView = [[GTVideoViewController alloc]init];

    videoView.view.backgroundColor = [UIColor whiteColor];
    videoView.navigationItem.title = @"视频页面";
    //	detailViewController.navigationItem.backButtonTitle = @"返回";
    [self.navigationController pushViewController:videoView animated:YES];
}

/// 页面跳转
- (void)pushController {
    NewsDetailViewController *detailView = [[NewsDetailViewController alloc]init];

    detailView.view.backgroundColor = [UIColor whiteColor];
    detailView.navigationItem.title = @"详情页面";
    //	detailViewController.navigationItem.backButtonTitle = @"返回";
    detailView.navigationItem.rightBarButtonItem = [[UIBarButtonItem alloc] initWithTitle:@"确定" style:UIBarButtonItemStylePlain target:self action:nil];
    [self.navigationController pushViewController:detailView animated:YES];
}

#pragma mark - Navigation
/*
   // In a storyboard-based application, you will often want to do a little preparation before navigation
   - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
   // Get the new view controller using [segue destinationViewController].
   // Pass the selected object to the new view controller.
   }
 */
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer {
    NSLog(@"gestureRecognizerShouldBegin");
    return YES;
}

@end
